import os

app_dir = r'/home/lukasz/workspace/CryptoFS/FS/'
mkfs_crypto = r'./mkfs.crypto'
crypto_fs = r'./CryptoFs'
import random
import time

#./fuse --key AA::22::33::44::55::66::77::88::01::22::33::44::55::66::77::88 -d -s --device ./tst.fs

def create_filesystem(file, key, group_count=1000, block_size=1024, blocks_per_group=245, inodes_per_group=240):
    dir = os.getcwd()
    os.chdir(app_dir)
    command = "%s -d %s --key %s --blockSize %d --blocksPerGroup %d --inodesPerGroup %d --groupNum %d  > /dev/null" % (mkfs_crypto, file, key, block_size, blocks_per_group, inodes_per_group, group_count)
    os.system(command) 
    #print command
    os.chdir(dir)
  
def mount_filesystem(mount_point, key, device):
    dir = os.getcwd()
    os.chdir(app_dir)
    umount_filesystem(mount_point)
    command = "%s %s --key %s  -s -d --device %s  2> /dev/null &" % (crypto_fs, mount_point, key, device) # -d -s 
    os.system(command)
    #print command
    os.chdir(dir)
    

def umount_filesystem(mount_point):
    dir = os.getcwd()
    os.chdir(app_dir)
    #time.sleep(2)
    command = "fusermount -u %s 2> /dev/null" % (mount_point)
    os.system(command)
    #print command
    os.chdir(dir)
    

def delete_filesystem(file):
    pass

def getBytes(patern, size):
    pat_len = len(patern)
    it = size / pat_len
    s= ""
    for i in range(0 , it):
        s += patern
    
    pat_rest_len = size%pat_len
    s+= patern[0:pat_rest_len]
    return s

def getRandText(size):
    s=""
    for i in range(0, size):
        s+= chr(random.randint(ord('a'), ord('z')))
    
    return s

if __name__ == '__main__':
    import sys
    #print sys.argv[1]
    #print getRandText(int(sys.argv[1]))
    print getRandText(1024*20+231)
